//
//  ScrollImageView.m
//  SecondPage
//
//  Created by xiong qi on 13-5-3.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "ScrollImageView.h"

@implementation ScrollImageView
@synthesize parentDelegate,imageview;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        
        imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 0)];
        [self addSubview:imageview];
        [imageview release];
    }
    return self;
}

-(void)SetImage:(UIImage *)image
{
    CGSize imagesize = image.size;
    int height = imagesize.height*self.frame.size.width /imagesize.width;
    imageview.frame = CGRectMake(0, 0, self.frame.size.width, height);
    imageview.image = image;
    
    self.contentSize = imageview.bounds.size;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (imageview.image == nil) {
        return;
    }
    if (parentDelegate != nil) {
        [self.parentDelegate ItemBeTouch:self];
    }
    else
    {
        [UIView animateWithDuration:0.4
                         animations:^{
                             
                             self.alpha = 0;
                         }
                         completion:^(BOOL finished){
                             [self removeFromSuperview];
                             
                         }];
    }

}

-(void)dealloc
{
    self.parentDelegate = nil;
    [super dealloc];
}


@end
